<?
JCAT_Package::ImportClass('JCAT_ArchiveDocument',JCAT::PACKAGE_DOC) ;

class ClassRegister extends JCAT_ArchiveDocument implements JCAT_ISingleton
{
	
	/**
	 * what's this
	 * @access	public
	 * @return	void
	 */
	public function ClassRegister()
	{
		$this->JCAT_ArchiveDocument(__CLASS__) ;
		
		$sPath = ROOT_PATH . 'Data/Archive/RegisteredClasses.dat' ;
		$this->SetPath( $sPath ) ;

		if( is_file($sPath) )
			$this->Load() ;
		else
			$this->Create() ;			
	}

	/**
	 * what's this
	 * 
	 * @access	public
	 * @param	$			what's this
	 * @return	array
	 */
	public function __destruct()
	{
		$this->Save() ;
	}
	
		
	/**
	 * what's this
	 * 
	 * @access	public
	 * @param	$sFunctonalName		string		功能名称
	 * @param	$sClassName			string		类名称
	 * @return	void
	 */
	public function AddClass($sFunctonalName,$sClassName)
	{
		JCAT_ASSERT::ASSERT_STRING($sFunctonalName) ;
		JCAT_ASSERT::ASSERT_STRING($sClassName) ;
		
		// 查询已有
		$arrClasses = $this->Get($sFunctonalName) ;
		if(!$arrClasses)
			$arrClasses = array() ;
		
		// 加入
		if( !in_array($sClassName,$arrClasses) )
			$arrClasses[] = $sClassName ;
		
		// 更新
		$this->Set($sFunctonalName,&$arrClasses) ;
	}
	
	
	/**
	 * what's this
	 * 
	 * @access	public
	 * @param	$sFunctonalName		string		功能名称
	 * @return	array
	 */
	public function CreateClassesIterator($sFunctonalName)
	{
		JCAT_ASSERT::ASSERT_STRING($sFunctonalName) ;
		
		$arrClasses = $this->Get($sFunctonalName) ;
		if(!$arrClasses)
			$arrClasses = array() ;
		
		return new JCAT_ArrayIterator($arrClasses) ;
	}
	/**
	 * what's this
	 * 
	 * @access	public
	 * @param	$sFunctonalName		string		功能名称
	 * @param	$sClassName			string		类名称
	 * @return	array
	 */
	public function RemoveClass($sFunctonalName,$sClassName)
	{
		JCAT_ASSERT::ASSERT_STRING($sFunctonalName) ;
		JCAT_ASSERT::ASSERT_STRING($sClassName) ;
		
		// 找到
		$arrClasses = $this->Get($sFunctonalName) ;
		$nIdx = array_search($sClassName,$arrClasses) ;
		
		// 移除
		if( $nIdx!==false )
			unset($arrClasses[$nIdx]) ;
		
		// 更新
		$this->Set($sFunctonalName,&$arrClasses) ;
	}
	
	// 属性 /////////////////////////////////////////////////////////////////////////////////

	
	
	
}


?>